home *** CD-ROM | disk | FTP | other *** search
- Path: news.rain.org!usenet
- From: "Guus Leeuw jr." <guusl@eiffel.com>
- Newsgroups: comp.lang.c++
- Subject: Re: delete or delete [] ?
- Date: Tue, 02 Apr 1996 08:28:21 -0800
- Organization: Interactive Software Engineering Inc. http://www.eiffel.com/
- Message-ID: <316155A5.3BA7E96A@eiffel.com>
- References: <4jp7n7$f8k@mcmail.CIS.McMaster.CA>
- NNTP-Posting-Host: @outback.eiffel.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; Linux 1.2.8 i586)
-
- Hong Shen wrote:
- >
- > In almost all of C++ literatures, "delete aa" should be used iff aa is not an
- > array and "delete [] aa" should be used iff aa is an array. In following case,
- > what should I use?
-
- Actually `delete [] aa' should only be used if the array contains non-standard
- types. Thus for `int *aa`, you should use `delete aa'.
-
- > typedef int int10[10];
- > int* aa=new int10; // array of 10 integers.
- >
- > delete aa;
- >
- > or
- >
- > delete [] aa;
-
- With the above and the below, this might not work always. I'm not too sure what the
- working paper says on this, but I think you can check that yourself :) Or better:
- have a look at the FAQ.
-
- >
- > For gcc (v2.6), it seems that both work. Which is the standard one?
-
- Not really. Last week I came across a `delete [] aa' where the program caught a
- SIGSEGV in `end()' after `delete [] mu_ints'. Further investigation taught me to
- use `delete my_ints' instead. (I tried the modification and all of a sudden it
- worked... :). BTW: I'm using g++ 2.6 as well.
-
- --
- 'l8r,
- Guus
- -------------------------------------------------------------------------
- They say I'm in need of some radical discipline.
- -- Jim Steinman (from the song: Rock'n'Roll Dreams Come Through)
- -------------------------------------------------------------------------
-